#ifndef _MEM_H_
#define _MEM_H_

#include <stdio.h>

#define zerror1(msg) \
  do {fprintf(stderr, "%s:%d:%s " msg, __FILE__, __LINE__, __func__);} while(0)
#define zerror2(msg, arg1) \
  do{fprintf(stderr, "%s:%d:%s " msg,__FILE__,__LINE__,__func__,arg1);}while(0)

/* allocate memory.*/
void* zmalloc(size_t nbytes) __attribute__ ((malloc));

/* allocate cleard memory */
void* zmalloc0(size_t nbytes) __attribute__((malloc));

/* reallocate memory */
void* zrealloc(void *mem, size_t nbytes) __attribute__((malloc));

/* free memory */
void zfree(void *mem);

#define z_new(struct_type, n)\
  ((struct_type *)zmalloc(sizeof(struct_type) * (n)))

#define z_new0(struct_type, n)\
  ((struct_type *)zmalloc0(sizeof(struct_type) * (n)))

#define z_renew(struct_type, mem, n)\
  ((struct_type *)zrealloc((mem), sizeof(struct_type)*(n)))


#endif /* _MEM_H_ */

